package com.saver.view.adapter;

import java.util.List;

import com.saver.R;
import com.saver.core.domain.Categoria;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CategoriaListAdapter extends ArrayAdapter<Categoria> {

	private List<Categoria> categorias;
	
	public CategoriaListAdapter(Context context, List<Categoria> categorias) {
		super(context, R.layout.item_row_layout, categorias);
		this.categorias = categorias;
	}
	
	@Override
	public View getView(int position, View contentView, ViewGroup parent) {
		if (contentView == null) {
			LayoutInflater inflater = (LayoutInflater) getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			contentView = inflater.inflate(R.layout.item_row_layout, null);
		}

		Categoria item = categorias.get(position);

		TextView text = (TextView) contentView.findViewById(R.id.label);
		text.setText(item.getNombre());

		return contentView;
	}

	@Override
	public int getCount() {
		return categorias.size();
	}

	@Override
	public Categoria getItem(int position) {
		return categorias.get(position);
	}

	@Override
	public long getItemId(int position) {
		return categorias.get(position).getId();
	}

}
